home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The X-Philes (2nd Revision)
/
The X-Philes Number 1 (1995).iso
/
xphiles
/
hp48_1
/
real2fs
< prev
next >
Wrap
Text File
|
1995-03-31
|
2KB
|
55 lines
Newsgroups: comp.sys.hp48
Subject: R\->FS (Real to Fraction String) (*SHORT* utility)
Followup-To:
Distribution: world
Organization: State University of New York @ Buffalo
Keywords:
IHMO, this isn't something that warents posting to c.src.hp48.
I'll manually dump it in the archives at seq and wuarchive.
For a project I'm working on, I needed a routine to display a real with the
fraction part replaced by on of the fraction characters (188 thru 190,
decimal, in the ISO LAtin1 Character Set). As I often write these short
utilities in userlang first, to make sure they work, I came up with the
following. I thought some might find it useful themselves.
The syntax looks like:
( 1:Real ) ==> ( 1:String )
Where Real is any real, and the output string has the format:
"iiiiiiiiiif", where the i's are the integer part, and the f is the
fraction character (space, one-quarter, one-half, or three-quarters).
As my project will only need to use this on values less than one thousand,
I've made no attempt to deal with values whose absolute value is greater
than or equal to 1e10.
Also, if the value passed is negative, a minus sign will prepend the format
as described above. Again, all my values are >0, so I didn't bother.
Adding support for that would be trivial.
Here is the file:
%%HP: T(3)A(R)F(.);
@ R\->FS
@ Takes real in (-1e10,1e10) and returns string representing that number
@ with the fracion part replaced by either a sapce or the ISO-Latin1
@ fraction character closest to the original fractional part.
@ Posted by James H. Cloos, Jr. Use at will.
@ cloos@acsu.buffalo.edu ;; cloos@ub.UUCP
\<< RCLF STD SWAP 4 * 0 RND 4 / DUP IP SWAP FP
IF DUP
THEN 4 * ABS 187 + CHR
ELSE DROP " "
END + SWAP STOF
\>>
-JimC
--
James H. Cloos, Jr. Phone: +1 716 673-1250
cloos@ACSU.Buffalo.EDU Snail: PersonalZipCode: 14048-0772, USA
cloos@ub.UUCP Note: Phone & Snail to change soon!